package cn.ekuma.impexp.ui.swing;

import java.awt.BorderLayout;
import java.util.HashMap;
import java.util.List;

import cn.ekuma.impexp.ImpExpManager;
import cn.ekuma.impexp.engine.csv.CSVEngine;
import cn.ekuma.impexp.model.ImpExpTableDefinition;

import com.openbravo.data.basic.BasicException;
import com.openbravo.data.gui.muleSelecter.MuleComboBoxValEntry;
import com.openbravo.data.gui.selecter.JObjectSelecter;
import com.openbravo.data.loader.TableDefinition;

import net.sourceforge.jwizardcomponent.JWizardComponents;
import net.sourceforge.jwizardcomponent.JWizardPanel;

import javax.swing.JFileChooser;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.File;

public abstract class JSelectTableWizardPanel extends JWizardPanel{

	JObjectSelecter tableSelecter;
	JTextField txtImportFileName;
	public JSelectTableWizardPanel(JWizardComponents wizardComponents,List<MuleComboBoxValEntry> entrys) {
		super(wizardComponents);
		tableSelecter=new JObjectSelecter(entrys);
		add(tableSelecter,BorderLayout.CENTER);
		
		JPanel panel = new JPanel();
		add(panel, BorderLayout.SOUTH);
		
		JLabel label = new JLabel("导入文件");
		panel.add(label);
		
		txtImportFileName = new JTextField();
		panel.add(txtImportFileName);
		txtImportFileName.setColumns(40);
		
		JButton btnSelectFile = new JButton("浏览");
		btnSelectFile.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				selectImportFile();
			}
		});
		panel.add(btnSelectFile);
		
	}

	protected void selectImportFile() {
		JFileChooser fileChooser = new JFileChooser();//创建文件选择框
		 this.txtImportFileName.setText("");//将文本域中的内容清空
		 fileChooser.setApproveButtonText("确定");
		 int result = fileChooser.showOpenDialog(this);
		 if(result==JFileChooser.APPROVE_OPTION){//选择的是确定按钮
		    File file = fileChooser.getSelectedFile();//得到选择的文件
		    txtImportFileName.setText(file.getPath());
		 }
	}

	@Override
	public void loadCurrentProperty(HashMap map) {
	}

}
